//
//  NoticeCell.swift
//  Employee
//
//  Created by swordjoy on 2017/3/31.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class NoticeCell: UITableViewCell {
  
  static var identifier = "NoticeCell.swordjoy"
  
  static func height(with string: String) -> CGFloat {
    return 122 + UIFont.calculateHeight(width: UIScreen.width - 70, font: GlobalConfig.system15Font, text: string)
  }

  var model: Notice? {
    didSet {
      guard let temp = model else { return }
      
      timeLabel.text =  DateHelper.getFormatTime(timeInmillisecond: temp.time) 
      titleLabel.text = temp.title
      contentLael.text = temp.content
    }
  }
  
  
  fileprivate var contentV: UIView!
  
  fileprivate var timeLabel: UILabel!
  fileprivate var titleLabel: UILabel!
  fileprivate var contentLael: UILabel!
  
  // MARK: - life cycle
  override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    backgroundColor = UIColor.clear
    selectionStyle = .none
    
    create()
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
  
}

// MARK: - fileprivate

extension NoticeCell {
  
  fileprivate func create() {
    
    timeLabel = UILabel()
    contentView.addSubview(timeLabel)
    timeLabel.font = GlobalConfig.system14Font
    timeLabel.textColor = GlobalConfig.TextLightColor
    timeLabel.snp.makeConstraints { (make) in
      make.centerX.equalToSuperview()
      make.top.equalTo(15)
    }
    
    contentV = UIView()
    contentView.addSubview(contentV)
    contentV.backgroundColor = UIColor.white
    contentV.snp.makeConstraints { (make) in
      make.left.equalTo(10)
      make.right.equalTo(-10)
      make.top.equalTo(timeLabel.snp.bottom).offset(15)
      make.bottom.equalToSuperview()
    }
    contentV.layer.cornerRadius = 4
    contentV.clipsToBounds = true
    
    titleLabel = UILabel()
    contentV.addSubview(titleLabel)
    titleLabel.font = GlobalConfig.system16Font
    titleLabel.textColor = GlobalConfig.BGSkyBlueColor
    titleLabel.snp.makeConstraints { (make) in
      make.left.equalTo(25)
      make.top.equalTo(20)
    }
    
    contentLael = UILabel()
    contentV.addSubview(contentLael)
    contentLael.font = GlobalConfig.system15Font
    contentLael.textColor = GlobalConfig.TextDeepColor
    contentLael.numberOfLines = 0
    contentLael.snp.makeConstraints { (make) in
      make.left.equalTo(25)
      make.right.equalTo(-25)
      make.top.equalTo(titleLabel.snp.bottom).offset(15)
    }
    
    
  }
  
}
